const path = require('path');
const webpack = require('webpack');
var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
var ExtractTextPlugin = require('extract-text-webpack-plugin');

const config = {
	target: 'node',
	output: {
		filename: '[name].js',
		libraryTarget: 'commonjs2'
	},
	context: __dirname,
	node: { console: true,
		global: true,
		process: true,
		Buffer: true,
		__filename: true,
		__dirname: true,
		setImmediate: true
	},
	module: {
		rules: [
			{
				test: /\.css$/,
				loader: ExtractTextPlugin.extract({
					fallback: "style-loader",
					use:['css-loader']
				})
			},
			{
				test : /\.less$/,
				loader: ExtractTextPlugin.extract({
					fallback: "style-loader",
					use:['css-loader','less-loader']
				})
			},
			{
				test: /\.(js)$|\.(jsx)$/,
				use: 'babel-loader',
				exclude: /node_modules/
			}
		]
	},
	stats: {
		colors: true
	},
	plugins: [
		new webpack.optimize.UglifyJsPlugin({
			sourceMap: false
		}),
		new ExtractTextPlugin({
			filename: "[name].css",
			disable: false,
			allChunks: true
		}),
		/*
		new webpack.optimize.CommonsChunkPlugin({
			name: "vendor"
		}),
		*/
		new webpack.ProvidePlugin({
			React: 'react',
			ReactDOM: 'react-dom',
			$: "jquery",
			jQuery: "jquery",
			moment:"moment"
		})
	],
	externals: {
		React: 'React',
		ReactDOM: 'react-dom',
	}
};

module.exports = config;
